/**
 * Moondance UML modeling tool
 * 
 * This program is free software; you can redistribute it and
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 3
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

package ro.pub.cs.se.moondance.editpolicy;

import org.eclipse.gef.EditPart;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editpolicies.FlowLayoutEditPolicy;
import org.eclipse.gef.requests.CreateRequest;

import ro.pub.cs.se.moondance.command.AttributeCreateCommand;
import ro.pub.cs.se.moondance.command.OperationCreateCommand;
import ro.pub.cs.se.moondance.editpart.ClassEditPart;
import ro.pub.cs.se.moondance.model.ClassFunction;
import ro.pub.cs.se.moondance.model.ClassVariable;
import ro.pub.cs.se.moondance.model.UMLBaseClass;

/**
 * Edit policy for Class as a container, handling functionality for dropping new
 * attributes and operations into classes
 */
public class ClassLayoutEditPolicy extends FlowLayoutEditPolicy {

	protected Command createAddCommand(EditPart child, EditPart after) {
		return null;
	}

	protected Command createMoveChildCommand(EditPart child, EditPart after) {
		return null;
	}

	/**
	 * @param request
	 * @return command to handle adding a new attribute/operation
	 */
	protected Command getCreateCommand(CreateRequest request) {
		Object newObject = request.getNewObject();
		if (newObject instanceof ClassVariable) {
			ClassEditPart classPart = (ClassEditPart) getHost();
			UMLBaseClass _class = classPart.getClassModel();
			ClassVariable attribute = (ClassVariable) newObject;
			AttributeCreateCommand command = new AttributeCreateCommand(_class,
					attribute);
			return command;
		}
		if (newObject instanceof ClassFunction) {
			ClassEditPart classPart = (ClassEditPart) getHost();
			UMLBaseClass _class = classPart.getClassModel();
			ClassFunction operation = (ClassFunction) newObject;
			OperationCreateCommand command = new OperationCreateCommand(_class,
					operation);
			return command;
		}
		return null;
	}

	/**
	 * @param request
	 * @return
	 */
	protected Command getDeleteDependantCommand(Request request) {
		return null;
	}

}